package com.niiwoo.civet.trade.service.local.notify.impl;

import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.enums.NotifyTypeEnum;
import com.niiwoo.civet.user.dto.request.AppButtonDTO;
import com.niiwoo.civet.user.dto.request.UserLetterRequestDTO;
import com.niiwoo.civet.user.enums.MessageTemplateKeyEnum;
import com.niiwoo.civet.user.enums.SMSTemplateKeyEnum;
import com.niiwoo.civet.user.enums.UserLetterTypeEnum;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Component
public class ProjectFlowMiscarryAutoFailedNotifier extends AbstractBorrowNotifier<Project> {

    // JS023 极速借被自动审核模型拒绝，导致流标
    // 借款人
    // 通知+极光推送: 抱歉，借款发布失败 / "您好，您的借款项目【项目名称】未能通过审核，暂时无法借款。原因为：[系统审核不通过，暂不符合借款要求]，如有疑问可咨询钱小二."
    @Override
    protected UserLetterRequestDTO getUserLetterRequestDTO(UserNotifyInfo info) {
        BorrowUserNotifyInfo p = (BorrowUserNotifyInfo) info;
        UserLetterRequestDTO letterRequest = new UserLetterRequestDTO();
        // 通知
        List<Object> letterParams = Arrays.asList(p.getProjectId(), p.getProjectTitle());
        letterRequest.setLetterTemplateEnum(MessageTemplateKeyEnum.LetterTemplateKeyEnum.PROJECT_FLOW_MISCARRY_AUTO_FAILED);
        letterRequest.setLetterTemplateParamList(letterParams);
        // 按钮
        AppButtonDTO buttonDTO = new AppButtonDTO();
        buttonDTO.setButtonType(AppButtonDTO.ButtonTypeEnum.MONEY_2);
        buttonDTO.setLabel(AppButtonDTO.ButtonTypeEnum.MONEY_2.getDesc());
        letterRequest.setLetterButtonList(Collections.singletonList(buttonDTO));
        // 极光推送
        List<Object> pushParams = Collections.singletonList(p.getProjectTitle());
        letterRequest.setJpushTemplateKeyEnum(MessageTemplateKeyEnum.JPushTemplateKeyEnum.PROJECT_FLOW_MISCARRY_AUTO_FAILED);
        letterRequest.setJpushTemplateParamList(pushParams);
        letterRequest.setToUserId(p.getUserId());
        letterRequest.setProjectId(p.getProjectId());
        letterRequest.setUserLetterTypeEnum(UserLetterTypeEnum.LETTER_AND_JPUSH);
        return letterRequest;
    }

    @Override
    protected SMSTemplateKeyEnum getSMSTemplateKey() {
        return SMSTemplateKeyEnum.PROJECT_FLOW_MISCARRY_AUTO_FAILED;
    }

    @Override
    protected NotifyTypeEnum getType() {
        return NotifyTypeEnum.JS023;
    }

}
